
import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react';

type Role = 'student' | 'teacher' | null;

interface RoleContextType {
  role: Role;
  setRole: (role: Role) => void;
  switchRole: () => void;
}

const RoleContext = createContext<RoleContextType | undefined>(undefined);

export const useRole = () => {
  const context = useContext(RoleContext);
  if (context === undefined) {
    throw new Error('useRole must be used within a RoleProvider');
  }
  return context;
};

interface RoleProviderProps {
  children: ReactNode;
}

export const RoleProvider = ({ children }: RoleProviderProps) => {
  const [role, setRoleState] = useState<Role>('teacher'); // 默认身份为 teacher

  // 移除 localStorage 相关逻辑，始终为 student
  const setRole = (newRole: Role) => {
    setRoleState(newRole);
  };

  // 移除 switchRole 逻辑，始终为 student
  const switchRole = () => {};

  return (
    <RoleContext.Provider value={{ role, setRole, switchRole }}>
      {children}
    </RoleContext.Provider>
  );
};
